package com.example.yiwei.crm.view.activity.coordinationActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.BaseActivity;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.data.GetCoorGifeData;
import com.example.yiwei.crm.json.GiftJson;
import com.example.yiwei.crm.util.NetWorkUtils;
import com.example.yiwei.crm.util.SC;

import org.json.JSONException;
import org.json.JSONObject;


public class GifeSearchActivity extends BaseActivity {
    private EditText editText1,editText2;
    SharedPreferences sp;
    private ImageView img_commit;
    int id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gife_search);
        editText1 = (EditText) findViewById(R.id.edit_seacher_1);
        editText2 = (EditText) findViewById(R.id.edit_seacher_2);
        img_commit= (ImageView) findViewById(R.id.health_education_img_commit);
        sp = getSharedPreferences("login", Context.MODE_PRIVATE);
        editText2.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
        img_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        SC sc=new SC();
                        JSONObject object = sc.storage(sp);
                        try {
                            object.put("KXA01",getIntent().getExtras().getInt("id"));
                            object.put("KDB02",editText1.getText().toString());
                            object.put("KDB03",editText2.getText().toString());
//                            object.put("DEL01",0);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        String json = object.toString();
                        String result = NetWorkUtils.getCount(baseClass.find_coor_gift_URL+1,json);
                        GetCoorGifeData.creat();
                        GetCoorGifeData.list = GiftJson.get(result);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (GetCoorGifeData.list!=null){
                                    finish();
                                }else {
                                    Toast.makeText(GifeSearchActivity.this, "此条件下查询不到信息", Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                    }
                }).start();
            }
        });

    }
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.health_education_img_back:
                finish();
                break;

        }
    }
}
